package com.wjc.train.business.controller;

import com.wjc.train.business.req.ConfirmOrderSaveReq;
import com.wjc.train.business.service.IBeforeConfirmOrderService;
import com.wjc.train.business.service.IConfirmOrderService;
import com.wjc.train.common.resp.CommonResp;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 确认订单表 前端控制器
 * </p>
 *
 * @author Guessed
 * @since 2023-08-15
 */
@RestController
@Validated
@RequestMapping("/confirm-order")
public class WebConfirmOrderController {

    @Resource
    private IConfirmOrderService confirmorderService;

    @Resource
    private IBeforeConfirmOrderService beforeConfirmOrderService;

    /**
     * 保存订单信息
     *
     * @param confirmorderSaveReq
     * @return
     */
    @PostMapping("/do")
    public CommonResp doConfirm(@RequestBody @Valid ConfirmOrderSaveReq confirmorderSaveReq){
        Long orderId = beforeConfirmOrderService.beforeDoConfirm(confirmorderSaveReq);
        return CommonResp.success(String.valueOf(orderId));
    }

    @GetMapping("/query-queue-count/{id}")
    public CommonResp queryQueue(@PathVariable Long id){
        Integer count = confirmorderService.queryQueue(id);
        return CommonResp.success(count);
    }

    @GetMapping("/cancelQueue/{id}")
    public CommonResp cancelQueue(@PathVariable Long id){
         confirmorderService.cancelQueue(id);
        return CommonResp.success();
    }
}


